{extend name="public/layout" /}
{block name="head"}{/block}
{block name="body"}

<body>
<div class="container-fluid p-t-15">
  <div class="card p-15">
    <div class="p-b-10">
      <a href="javascript:void(0);" onclick="doAction.add()" class="btn btn-primary">
        <i class="mdi mdi-plus"></i> 添加
      </a>
      <a href="javascript:void(0);" class="btn btn-default" onclick="doAction.refresh();">
        <i class="mdi mdi-refresh"></i> 刷新
      </a>
    </div>
    <div class="table-responsive">
      <table id="grid" class="table table-bordered">
        <thead>
        <tr>
          <th style="width:60px">ID</th>
          <th>权限名称</th>
          <th>权限标识</th>
          <th style="width:120px;">状态</th>
          <th style="width:120px">排序</th>
          <th style="width:250px">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr class="treegrid-{$vo.id} {gt name='$vo.pid' value='0'} treegrid-parent-{$vo.pid}{/gt}">
          <td>{$vo.id}</td>
          <td>{$vo.title}</td>
          <td>{$vo.name}</td>
          <td>
            {:\\helper\\Form::_switch('status',$vo.status,[
            "data-id"=>$vo['id']
            ])}
          </td>
          <td>{$vo.show_order}</td>
          <td>
            <a href="javascript:void(0)" onclick="doAction.add('{$vo.id}')" class="btn-xs btn btn-info">
              <i class="mdi mdi-plus"></i> 添加</a>
            <a href="javascript:void(0)" onclick="doAction.edit('{$vo.id}')" class="btn-xs btn btn-primary">
              <i class="mdi mdi-pencil"></i> 编辑</a>
            <a href="javascript:void(0)" class="btn-xs btn btn-danger" onclick="helper.doConfirm(this,'refresh')"
               data-url="del.html" data-params="id={$vo.id}" data-msg="确认要删除该规则吗?"><i class="mdi mdi-archive"></i>
              删除</a>
          </td>
        </tr>
        {/volist}
        </tbody>
      </table>
    </div>
  </div>
</div>
<script>
  helper.treeTable({ treeColumn: 1 });
  //分类状态切换
  $("input[name='status']").change(function () {
    var that = $(this);
    var id = that.data('id');
    layer.confirm('确认变更状态吗?', {icon: 3},
        function (index) {
          helper.getAjax({
            url: '/system/auth_rule/set.html',
            data: {id: id},
            success: function (res) {
              if (res.code == 0) {
                that.prop("checked", !$(that).prop("checked"));
                helper.tips(res.msg);
              }
              layer.close(index);
            }
          })
        },
        function (index) { //取消按钮
          that.prop("checked", !that.prop("checked"));
          layer.close(index);
        }
    )
  });
  var doAction = {
    add: function (id) {
      var url = id ? '/system/auth_rule/add.html?pid=' + id : '/system/auth_rule/add.html';
      layer.open({
        type: 2,
        title: "添加规则",
        offset: "30px",
        area: helper.layerMedia('800px','420px'),
        content: url
      });
    },
    edit: function (id) {
      var url = '/system/auth_rule/edit.html?id=' + id;
      layer.open({
        type: 2,
        title: "修改规则",
        offset: "30px",
        area: helper.layerMedia('800px','420px'),
        content: url
      });
    },
    refresh: function () {
      helper.getAjax({
        url: "refresh.html",
        success: function (res) {
          if (res.code == 1) {
            helper.refresh();
          } else {
            helper.tips(res.msg);
          }
        }
      });
    }
  };
</script>
</body>
{/block}